package com.changgou.service.goods.service.impl;

import com.changgou.goods.pojo.Brand;
import com.changgou.service.goods.dao.BrandMapper;
import com.changgou.service.goods.service.BrandService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper brandMapper;

    //查询所有品牌信息
    @Override
    public List<Brand> findAll() {
        List<Brand> list = brandMapper.selectAll();
        return list;
    }

    //根据id查询品牌信息
    @Override
    public Brand findById(int id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    //根据id删除品牌
    @Override
    public void delById(int id) {
        brandMapper.deleteByPrimaryKey(id);
    }

    //添加品牌
    @Override
    public void add(Brand brand) {
        brandMapper.insertSelective(brand);
    }

    //修改品牌
    @Override
    public void updateById(Brand brand) {
        brandMapper.updateByPrimaryKeySelective(brand);
    }

    @Override
    public Page<Brand> page(int pageNumber,int pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<Brand> brands = brandMapper.selectAll();
        Page<Brand> brandPage = (Page<Brand>)brands;
        return brandPage;
    }

    @Override
    public Page<Brand> selectByCondition(String str) {
        Page<Brand> brands = brandMapper.selectByCondition(str);
        return brands;
    }

}
